package com.yunhe.portal.controller;

import com.yunhe.common.model.ResultObject;
import com.yunhe.common.model.mybatis.PageResult;
import com.yunhe.portal.domain.DataBannerInfo;
import com.yunhe.portal.domain.DataNewsInfo;
import com.yunhe.portal.domain.DataNoticeInfo;
import com.yunhe.portal.model.DataBannerInfoVo;
import com.yunhe.portal.model.DataNewsInfoVo;
import com.yunhe.portal.model.PhoneQueryCondition;
import com.yunhe.portal.service.DataBannerInfoService;
import com.yunhe.portal.service.DataNewsInfoService;
import com.yunhe.portal.service.DataNoticeInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName PortalController
 * @Description TODO
 * @Author HeTao
 * @Date 2021/10/19 11:43
 * @Version 1.0
 **/
@Api(value = "portal", description = "门户接口", tags = {"门户接口"})
@RestController
@RequestMapping(value = "/portal")
public class PortalController {

    @Autowired
    private DataNewsInfoService dataNewsInfoService;

    @Autowired
    private DataNoticeInfoService dataNoticeInfoService;

    @Autowired
    private DataBannerInfoService dataBannerInfoService;

    @ApiOperation("查询app新闻")
    @PostMapping("/findAppNews")
    public ResponseEntity<ResultObject<List<DataNewsInfoVo>>> findAppNews(@RequestBody PhoneQueryCondition phoneQueryCondition){
        PageResult result = dataNewsInfoService.findAppNews(phoneQueryCondition);
        return new ResponseEntity<>(new ResultObject(result), HttpStatus.OK);
    }

    @ApiOperation("根据idApp查询新闻表")
    @GetMapping("/findAppDataNewsInfoById")
    public ResponseEntity<ResultObject<DataNewsInfo>> findAppDataNewsInfoById(@RequestParam(value = "id",required = true) int id){
        return new ResponseEntity<>(new ResultObject(dataNewsInfoService.findDataNewsInfoById(id)),HttpStatus.OK);
    }

    @ApiOperation("根据idWeChat查询新闻表")
    @GetMapping("/findWeChatDataNewsInfoById")
    public ResponseEntity<ResultObject<DataNewsInfo>> findWeChatDataNewsInfoById(@RequestParam(value = "id",required = true) int id){
        return new ResponseEntity<>(new ResultObject(dataNewsInfoService.findDataNewsInfoById(id)),HttpStatus.OK);
    }


    @ApiOperation("查询小程序新闻")
    @PostMapping("/findWeChatNews")
    public ResponseEntity<ResultObject<List<DataNewsInfoVo>>> findWeChatNews(@RequestBody PhoneQueryCondition phoneQueryCondition){
        PageResult result = dataNewsInfoService.findWeChatNews(phoneQueryCondition);
        return new ResponseEntity<>(new ResultObject(result),HttpStatus.OK);
    }

    @ApiOperation("查询app公告信息")
    @PostMapping("/findAppNotice")
    public ResponseEntity<ResultObject<List<DataNewsInfoVo>>> findAppNotice(@RequestBody PhoneQueryCondition phoneQueryCondition){
        PageResult result = dataNoticeInfoService.findAppNotice(phoneQueryCondition);
        return new ResponseEntity<>(new ResultObject(result), HttpStatus.OK);
    }

    @ApiOperation("查询小程序公告消息")
    @PostMapping("/findWeChatNotice")
    public ResponseEntity<ResultObject<List<DataNewsInfoVo>>> findWeChatNotice(@RequestBody PhoneQueryCondition phoneQueryCondition){
        PageResult result = dataNoticeInfoService.findWeChatNotice(phoneQueryCondition);
        return new ResponseEntity<>(new ResultObject(result),HttpStatus.OK);
    }

    @ApiOperation("根据idApp查询公告表")
    @GetMapping("/findAppDataNoticeInfoById")
    public ResponseEntity<ResultObject<DataNoticeInfo>> findAppDataNoticeInfoById(@RequestParam(value = "id",required = true) int id){
        return new ResponseEntity<>(new ResultObject(dataNoticeInfoService.findPhoneDataNoticeInfoById(id)),HttpStatus.OK);
    }

    @ApiOperation("根据idWeChat查询公告表")
    @GetMapping("/findWeChatDataNoticeInfoById")
    public ResponseEntity<ResultObject<DataNoticeInfo>> findWeChatDataNoticeInfoById(@RequestParam(value = "id",required = true) int id){
        return new ResponseEntity<>(new ResultObject(dataNoticeInfoService.findPhoneDataNoticeInfoById(id)),HttpStatus.OK);
    }

    @ApiOperation("获取appBanner")
    @PostMapping("/findAppBanner")
    public ResponseEntity<ResultObject<List<DataBannerInfo>>> findAppBanner(@RequestBody PhoneQueryCondition phoneQueryCondition){
        List<DataBannerInfo> dataBannerInfoList = dataBannerInfoService.findAppBanner(phoneQueryCondition.getStationId());
        return new ResponseEntity<>(new ResultObject(dataBannerInfoList), HttpStatus.OK);
    }

    @ApiOperation("获取小程序Banner")
    @GetMapping("/findWeChatBanner")
    public ResponseEntity<ResultObject<List<DataBannerInfo>>> findWeChatBanner(@RequestParam Long stationId){
        List<DataBannerInfo> dataBannerInfoList = dataBannerInfoService.findWeChatBanner(stationId);
        return new ResponseEntity<>(new ResultObject(dataBannerInfoList),HttpStatus.OK);
    }
}
